-
Notifications
You must be signed in to change notification settings - Fork 263
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PHPLIB-1596 Fully describe $search
, $searchMeta
and $vectorSearch
stages
#1537
Conversation
$search
and $searchMeta
stages
e433932
to
ba5c7b9
Compare
$search
and $searchMeta
stages$search
, $searchMeta
and $vectorSearch
stages
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Taking a first pass and will leave more feedback on other YAML files later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this first review. I'll commit the fixes.
2ea8f3a
to
64e79e4
Compare
@@ -145,6 +147,8 @@ private function convertYamlTaggedValues(mixed $object): mixed | |||
'bson_decimal128' => new Decimal128($value), | |||
'bson_utcdatetime' => new UTCDateTime(is_numeric($value) ? $value : new DateTimeImmutable($value)), | |||
'bson_binary' => new Binary(base64_decode($value)), | |||
'bson_objectId' => new ObjectId($value), | |||
'bson_uuid' => new Binary(hex2bin(str_replace('-', '', $value)), Binary::TYPE_UUID), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because I was curious, I went back and compared the original code you had with pack('h*', ...)
. See below:
<?php
// Initialized project with: composer require ramsey/uuid
require 'vendor/autoload.php';
use Ramsey\Uuid\Uuid;
use MongoDB\BSON\Binary;
$uuid = Uuid::uuid4();
var_dump($uuid);
$bytes = $uuid->getBytes();
$str = $uuid->toString();
$bin = new Binary($bytes, Binary::TYPE_UUID);
var_dump(bin2hex($bin));
$bin2 = new Binary(hex2bin(str_replace('-','',$str)), Binary::TYPE_UUID);
var_dump($bin == $bin2);
$bin3 = new Binary(pack('h*', str_replace('-','',$str)), Binary::TYPE_UUID);
var_dump($bin == $bin3);
$bin4 = new Binary(pack('H*', str_replace('-','',$str)), Binary::TYPE_UUID);
var_dump($bin == $bin4);
Output:
$ php foo.php
class Ramsey\Uuid\Lazy\LazyUuidFromString#4 (2) {
private ?Ramsey\Uuid\UuidInterface $unwrapped =>
NULL
private string $uuid =>
string(36) "3a6224c2-f648-4978-b510-610c04fbbcd6"
}
string(32) "3a6224c2f6484978b510610c04fbbcd6"
bool(true)
bool(false)
bool(true)
So it looks like h
(hex string, low nibble first) wouldn't have worked, but H
(high nibble first) would have. hex2bin()
is totally fine, though, and easier to read.
|
||
# The various example from the doc are variations of the "query" parameter | ||
# this is not pertinent for testing the aggregation builder, unless we create | ||
# a queryString builder. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's not 😉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's review #1540 before going further.
use MongoDB\Tests\Builder\PipelineTestCase; | ||
|
||
/** | ||
* Test in search |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In fact, the search operators are not prefixed by the dollar sign 🤦.
I'll do a following PR to add quotes as this will impact all test classes (or maybe remove the comment).
9b22965
to
9fe3bd1
Compare
Fix PHPLIB-1596
The parameters of the
$search
and$searchMeta
stages are currently not described. Changing the generic property object into a full list of named arguments would be a breaking change after the first release of this code, so it's now or never.For the tests, you can see the deep structure of options is not described. That's something we an do later.
Group
andDollarGroup
, use property name map #1540OperatorInterface::getOperator()
withOperatorInterface::NAME
constant #1541